home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.lang.c
- Subject: Re: I need help.
- Date: 28 Mar 96 20:58:10 GMT
- Organization: CERN European Lab for Particle Physics
- Message-ID: <danpop.828046690@rscernix>
- References: <4j9hr7$skj@cronkite.seas.gwu.edu> <26MAR199615081545@erich.triumf.ca>
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <26MAR199615081545@erich.triumf.ca> bennett@erich.triumf.ca (P.Bennett) writes:
-
- >In article <4j9hr7$skj@cronkite.seas.gwu.edu>, celtik@gwis2.circ.gwu.edu (Tolga Celtikci) writes...
- >>Can anyone help me with the syntax of EOF. Is it '\o' or something else?
-
- The "syntax" of EOF is EOF. It works fine after including <stdio.h>.
-
- On _some_ platforms it can be even written as a character constant: '\xff'
- or '\377', but:
-
- 1. It is a very "efficient" way to obfuscate your code. Other people
- will have a very hard time figuring out what you meant.
-
- 2. It will work only on platforms which use two's complement integers,
- define EOF as -1 and treat char as an 8-bit signed type. OTOH, EOF
- works everywhere.
-
- >EOF is _not_ a char in the file. It is a value returned by getchar(), fgetc()
- >and some other functions to indicate that they have attempted to read past
- >end-of-file. It is a value that cannot be represented in a char, so getchar()
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Don't be so sure. Implementations with sizeof(char) == sizeof(int) are
- legal and even exist. They're a royal pain in the ass when it comes to
- testing for EOF, because EOF is also a valid character value, so after
- reading an EOF you have to call ferror and feof to disambiguate between
- a genuine char value and an end-of-file condition.
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-